/**
 * @date: 2021/9/14
 * @author jikaidi
 * @Description: 将sheet页列边界生成所有选项
 * @method processCol
 * @param {String} str sheet页最大边界列(此方法支持最大边界为'ZZZ')
 * @return {Array} 返回包含所有选项数组
 */
function processCol(str) {
  if (str.length === 1) {
    return createSrt(createSrt().indexOf(str) + 1);
  } else if (str.length === 2) {
    const strArr = str.split("");
    const newStrArr = strArr.map((item) => {
      return processCol(item);
    });
    const res = newStrArr[0].map((item, index) => {
      const arr = [];
      if (index === 0) {
        arr.push(...createSrt());
      }
      if (index !== newStrArr[0].length - 1) {
        createSrt().forEach((item2) => {
          arr.push(item + item2);
        });
        return arr;
      } else {
        newStrArr[1].forEach((item2) => {
          arr.push(item + item2);
        });
        return arr;
      }
    });
    const finalRes = [];
    res.forEach((item) => {
      finalRes.push(...item);
    });
    return finalRes;
  } else if (str.length === 3) {
    const strArr = str.split("");
    const newStrArr = processCol(strArr[0]);
    const res = newStrArr.map((item, index) => {
      const arr = [];
      if (index === 0) {
        arr.push(...processCol("ZZ"));
      }
      if (index !== newStrArr.length - 1) {
        processCol("ZZ").forEach((item2) => {
          if (item2.length === 2) {
            arr.push(item + item2);
          }
        });
      } else {
        processCol(strArr[1] + strArr[2]).forEach((item2) => {
          arr.push(item + item2);
        });
      }
      return arr;
    });
    const finalRes = [];
    res.forEach((item) => {
      finalRes.push(...item);
    });
    return finalRes;
  }
}

/**
 * @date: 2021/9/14
 * @author jikaidi
 * @Description: 生成一位字符串的数组
 * @method createSrt
 * @param {number} num 多少个字符 A-Z
 * @return {Array} 每项为单个字符的数组
 */
function createSrt(num = 26) {
  return [...Array(num).keys()].map((item) => String.fromCharCode(item + 65));
}

export { processCol };
